<template>
  <div class="login-wrap">
    <el-form :model="users" class="demo-ruleForm login-container">
      <h1 style="text-align: center;">你好, 请登录!</h1>
      <p style="text-align: center;">山东省高考志愿填报决策系统</p>
      <el-form-item style="text-align: center;">
        <el-input v-model="users.name" placeholder="用户名" style="width: 80%;"></el-input>
      </el-form-item>
      <el-form-item style="text-align: center;">
        <el-input type="password" v-model="users.password" placeholder="密码" style="width: 80%;"></el-input>
      </el-form-item>
      <el-form-item>
        <el-row>
          <el-col :span="24">
            <div class="grid-content bg-purple-dark" style="text-align: center;">
              <el-button type="primary" style="width:80%" @click="login">提交</el-button>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12" style="text-align: center;">
            <div class="grid-content bg-purple-dark">
              <el-link type="success" @click="toReg">用户注册</el-link>
            </div>
          </el-col>
          <el-col :span="12" style="text-align: center;">
            <div class="grid-content bg-purple-dark">
              <el-link type="success">忘记密码</el-link>
            </div>
          </el-col>
        </el-row>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
    export default {
        data() {
            return {
                users:{}
            };
        },
        methods: {
            toReg() {
                this.$router.push({
                    path: '/register'
                });
            },
            login(){    //登录
                this.$axios.post("http://localhost:8080/users/login", this.users).then((res)=>{
                    console.log(res.data);
                    if(res.data.state){
                        const storage = window.localStorage;
                        storage.setItem("online","on");
                        storage.setItem("userid",res.data.id)
                        this.$axios.get("http://localhost:8080/users/getUsersRoleById?id="+res.data.id).then((res2)=>{
                          storage.setItem("administrator",res2.data)
                        })
                        alert(res.data.msg + ",点击进入主页")
                        this.$router.push({
                            path: '/index'
                        });
                    }else {
                        alert(res.data.msg);
                    }
                })
            },
        },

    }
</script>

<style scoped>
  .login-wrap {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    padding-top: 10%;
    background-image: url();
    /* background-color: #112346; */
    background-repeat: no-repeat;
    background-position: center right;
    background-size: 100%;
  }

  .login-container {
    border-radius: 10px;
    margin: 0px auto;
    width: 600px;
    padding: 30px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    text-align: left;
    box-shadow: 0 0 20px 2px rgba(0, 0, 0, 0.1);
  }

  .title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
  }
</style>

